import os
import re

'''
毫秒转HH:mm:ss.ms
'''
def millsecondToTime(mill):
    second, ms = divmod(mill, 1000.0)
    m, s = divmod(second, 60.0)
    h, m = divmod(m, 60.0)
    result = "%02d:%02d:%02d.%02d" % (h, m, s, ms)
    return result

'''
执行命令行
command:命令
返回值：0,成功；1，失败
'''
def command_line(command):
    return os.system(command)


'''
   向文件中追加内容
'''
def writeLogger(fileName,content):
    with open(fileName, 'a') as file_object:
        file_object.write(content+"\n")
        file_object.close()

'''
    @:param command 命令行
    @:param callbackFunc 回调函数 成功函数传0 失败函数传-1
'''
def executeCommand(target,command,callbackFunc,delDir):
    code = command_line(command)
    if code == 0:
        print("成功！")
        callbackFunc(0,target,delDir)
    else:
        print("失败！")
        callbackFunc(-1,target,delDir)
    return code

'''
    @:param command 命令行
    @:param callbackFunc 回调函数 成功函数传0 失败函数传-1
'''
def tryExecuteCommand(command,callbackFunc,*params):
    code = command_line(command)
    if code == 0:
        print("成功！")
        callbackFunc(0,params)
    else:
        print("失败！")
        callbackFunc(-1,params)
    return code
